package com.ting.encrypt.handler;

import com.ting.encrypt.enums.SensitiveType;
import org.apache.commons.lang3.StringUtils;

/**
 *
 * @author guohaibing
 */
public class NameSensitiveHandler implements SensitiveTypeHandler {
    @Override
    public SensitiveType getSensitiveType() {
        return SensitiveType.CHINESE_NAME;
    }

    @Override
    public String handle(Object src) {
        if (src == null) {
            return "";
        }
        String name = String.valueOf(src);
        if (!StringUtils.isBlank(name) && name.length() != 1) {
            String markName = name.contains("(") ? name.substring(0, name.indexOf("(")) + "(*" + name.substring(name.indexOf("(") + 2) : "*" + name.substring(1);
            return markName;
        } else {
            return name;
        }
    }
}
